/**
 * Used for test.
 * @ignore
 */
function displayXML(xmlData)
{
//	console.log(xmlData);
	return debugXML( fleegix.xml.createDoc(xmlData).documentElement, '' );
}
/**
 * Used for test.
 * @ignore
 */
function debugXML(xmlElem, tabSum)
{
	//console.log( "XMLDOC: " + xmlElem );
	
	var tagopen = '';
	var tagclose = '';
	var obtained = '';
	
	if (xmlElem instanceof Element)
	{
		tagopen += tabSum + '&lt' + xmlElem.tagName;
		
		for (var i=0;i<xmlElem.attributes.length;++i)
		{
			tagopen += '&nbsp' + xmlElem.attributes[i].name;
			tagopen += '=' + xmlElem.attributes[i].nodeValue;
		}
		tagopen += '&gt';
			
		if (xmlElem.childNodes.length == 1 && !(xmlElem.childNodes[0] instanceof Element))
		{
			obtained = xmlElem.childNodes[0].nodeValue;
		}
		else if (xmlElem.childNodes.length !=  0)
		{
			tagopen += '<br/>';
			for (var i=0;i<xmlElem.childNodes.length;++i)
			{
				if (xmlElem.childNodes[i] instanceof Element)
				{
//					obtained += debugXML(xmlElem.childNodes[i], tabSum+'&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp');
					obtained += debugXML(xmlElem.childNodes[i], tabSum);
				}
				else
				{
					obtained = xmlElem.childNodes[i].nodeValue;
				}
			}
			tagclose += tabSum;
		}
		
		tagclose += '&lt/'+xmlElem.tagName+'&gt'+'<br/>';
		
//		console.log(tagopen +  obtained + tagclose);
		return tagopen +  obtained + tagclose;
	}
	else
	{
//		console.log(xmlElem.nodeValue);
		return xmlElem.nodeValue;
	}
	
	return {};
}
/**
 * Used for test.
 * @ignore
 */
function initView()
{
	var ncddservices = new NG.command.NCDDServices({
		runXmlUrl:URL_RUNXML2,
		workspaceName:'PENDIK_UTM',
		dataset:'MAHALLE.EGITIM.MAHALLE',
		layout:'MAHALLE'
		});

	var session = NGServiceRequester.isAlreadyLoggedIn("netadmin", URL_LOGIN2);
	console.log( "Already Logged With Session: " + session.getSessionID() );
	
	NGServiceRequester.executeCommand(ncddservices, session.getSessionID(), {
    	requestFinished: function (response) {
    		var ncddresponse = ncddservices.getResponse(response);
    		
    		var getinfoex = new NG.command.GetInfoEx({
    			runXmlUrl:URL_RUNXML2,
    			workspaceName:'PENDIK_UTM',
    			SRID:"4326",
    			proj:'',
//    			FAD: ncddresponse.getResultTableList(),
    			FAD: ncddresponse.getResultList(),
    			clockwise: 'False',
    			countOnly: 'False',
    			intersects:{propertyName: 'Geometry', point:{coordinates:'385514.709250495 118401.34057266'}}
    		});
    		
//    		console.log( getinfoex.getDataXML() );
    		
    		NGServiceRequester.executeCommand(getinfoex, session.getSessionID(), {
    	    	requestFinished: function (response) {
    	    		getinfoex.getResponse(response);
//    	    		console.log(response);
//    	    		var sonuc = displayXML(fleegix.xml.parse(fleegix.xml.createDoc(response), 'string').string);
//    	    		document.getElementById("asd").innerHTML = displayXML(fleegix.xml.parse(fleegix.xml.createDoc(sonuc), 'wfs:FeatureCollection'));
    	    	}
    	    });
    	}
    });
	

	
	
//	document.getElementById("asd").innerHTML = displayXML(mytext);
}
/**
 * Used for test.
 * @ignore
 */
app.views.DenemeView = Ext.extend(Ext.Panel, {
    dockedItems: [{
        xtype: 'toolbar',
        title: 'View XML',
        items: [
            {
                text: 'Geri Don Geri Don',
                ui: 'back',
                listeners: {
                    'tap': function () {
                        Ext.dispatch({
                            controller: app.controllers.deneme,
                            action: 'back',
                            animation: {type:'slide', direction:'right'}
                        });
                    }
                }
            },
            {xtype:'spacer'}
        ]
    }],
    items:[{
		html:'<p id="XML Viewer">Viewing Generated XML</p>' +
		'<div id="asd"/>'
		,listeners:{
			afterrender: function (component) {
				
				initView();
			}
		}
    }],
    styleHtmlContent:true,
    scroll: 'vertical',
    
    /**
     * Used for test.
     * @ignore
     */
    updateWithRecord: function(record) {
        Ext.each(this.items.items, function(item) {
            item.update(record.data);
        });
    },
	/**
	 * Used for test.
	 * @ignore
	 */
	initComponent: function() {
		app.views.DenemeView.superclass.initComponent.apply(this, arguments);
	},
	/**
	 * Used for test.
	 * @ignore
	 */
	renderWorkspace: function(workspace) {
		this.workspace = workspace;
		initView();
		this.doLayout();
	}
});

